package com.ying.tests.CCCbasis.Test5ThreadPool;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class Test5ThreadPoolDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 创建线程池对象
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        // 创建一个Callable接口子类对象
        TaskCallableDemo task1 = new TaskCallableDemo();
        TaskCallableDemo task2 = new TaskCallableDemo();

        //<Integer> Future<Integer> submit(Callable<Integer> task)
        Future<Integer> result = executorService.submit(task1);
        Integer sum = result.get();
        System.out.println("sum = " + sum);

        result = executorService.submit(task2);
        sum = result.get();
        System.out.println("sum = " + sum);

        executorService.shutdown();

    }

}
